<template>
  <div>
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>课程列表</span>
          <el-button class="button" type="text">Operation button</el-button>
        </div>
      </template>
      <div style="text-align: center;height: 300px">
        <el-table :data="tableData" style="width: 100%" height="350">
          <el-table-column fixed prop="id" label="序号" width="150" />
          <el-table-column prop="name" label="课程名称" width="120" />
          <el-table-column prop="time" label="创建时间" width="120" />
          <el-table-column label="可见状态" width="200">
            <template #default="scope">
              <el-switch v-model="tableData[scope.$index].sw" @change="Switch(scope.row)"/>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="600">
            <template #default="scope">
              <el-button @click="edit(scope.row)"><img src="../../img/bj.jpg" width="20" height="20"></el-button>
              <el-button @click="gl(scope.row)"><img src="../../img/zy.png" width="20" height="20"></el-button>
              <el-button @click="bj1(scope.row)"><img src="../../img/bp.png" width="20" height="20"></el-button>
              <el-button @click="bj2(scope.row)"><img src="../../img/kk.png" width="20" height="20"></el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <div v-if="show" style="text-align: center">正在{{operation}}{{curriculum}}</div>
  </div>
</template>

<script>
import { ElMessage } from 'element-plus'
export default {
  name: 'courseList',
  data(){
    return{
      tableData:[
        {
          id:'1',
          name:'Java程序设计',
          time:'2020-12-12',
          sw:true,
        },
        {
          id:'2',
          name:'Mysql数据库技术',
          time:'2020-12-11',
          sw:false,
        },
        {
          id:'3',
          name:'Web前端开发基础',
          time:'2020-12-11',
          sw:true,
        },
        {
          id:'4',
          name:'Web前端开发实战项目',
          time:'2020-12-11',
          sw:true,
        },
      ],
      operation:'',
      curriculum:'',
      show:false,
    }
  },
  methods:{
    bj1(scope){
      this.show=true
      this.curriculum=scope.name
      this.operation='资源编排'
    },
    bj2(scope){
      this.show=true
      this.curriculum=scope.name
      this.operation='开课'
    },
    edit(scope){
      this.show=true
      this.curriculum=scope.name
      this.operation='编辑'
    },
    gl(scope){
      this.show=true
      this.curriculum=scope.name
      this.operation='资源管理'
    },
    Switch(scope){
      if (scope.sw==true){
        ElMessage({
          message:scope.name+'是可见的',
          type:'success'
        })
      }else {
        ElMessage({
          message:scope.name+'是不可见的',
          type:'warning'
        })
      }
    }
  }
}
</script>

<style scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.box-card {
  width:90%;
  margin-left: 5%;
}
</style>
